# -- coding: utf-8 --
import json

from flask import Blueprint, render_template, request
from Module_Blueprint.Tools_Templates.tools_code.Base64_tools.Base64_encodeAnddecode import B64


Tools_bp = Blueprint('Tools_BluePrint', __name__, template_folder="templates", static_folder="response_file")


# @Tools_bp.route('/tools_index')
# def Tools_index():
#     return render_template('tools_index.html')


@Tools_bp.route('/Base64_tools',  methods=['GET', 'POST'])
def Base64_tools():
    data = request.form
    if request.method == 'GET':
        return render_template('Base64_tools.html')
    if data:
        befor_data = data.get('befor_data')
        submit_type = data.get('submit_type')
        # base64 转码
        after_data = B64.Data_conversion_func(submit_type, befor_data)
    else:
        return render_template('Base64_tools.html')

    return render_template('Base64_tools.html', befor_data=befor_data, after_data=after_data)


@Tools_bp.route('/Md5_tools',  methods=['GET', 'POST'])
def Md5_tools():
    from Module_Blueprint.Tools_Templates.tools_code.Md5_tools.MD5_encode import Md5_encode_func

    data = request.form
    if request.method == 'GET':
        return render_template('Md5_tools.html')
    if data:
        # MD5加密
        encode_befor_data = data.get('befor_data')
        encode_after_data = Md5_encode_func(encode_befor_data)
    else:
        return render_template('Md5_tools.html')

    return render_template('Md5_tools.html', befor_data=encode_befor_data, after_data=encode_after_data)



@Tools_bp.route('/JKDT_tools',  methods=['GET', 'POST'])
def JKDT_tools():
    from Module_Blueprint.Tools_Templates.tools_code.JKDT_poOrderSivece.JKDT_POOrderService import JKDT_repose

    data = request.form
    if request.method == 'GET':
        return render_template('JKDT_response.html')
    if data:
        # 生成JKDT报文
        encode_befor_data = data.get('befor_data')
        json_data = json.loads(encode_befor_data)
        encode_after_data = JKDT_repose(json_data)
    else:
        return render_template('JKDT_response.html')

    return render_template('JKDT_response.html', befor_data=encode_befor_data, after_data=encode_after_data)